//
//  InitViewController.m
//  HollyPhoneSdk
//
//  Created by hollycrm on 2023/3/23.
//

#import "InitViewController.h"
#import "Utils.h"
#import "HollyPhoneManager.h"

@interface InitViewController ()
{
    UILabel *stateLabel;
    UIActivityIndicatorView *indicator;
    NSBundle *bundle;
    UIButton *backBt;
}
@end

@implementation InitViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    CGFloat screenw = UIScreen.mainScreen.bounds.size.width;
    CGFloat screenh = UIScreen.mainScreen.bounds.size.height;
    
   // [self.view addSubview:[Utils getBlurBg]];
    self.view.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
   
    
    stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, screenh/3, screenw, 40)];
    [stateLabel setTextColor:UIColor.whiteColor];
    [stateLabel setFont:[UIFont systemFontOfSize:15.0]];
    [stateLabel setTextAlignment:NSTextAlignmentCenter];
    stateLabel.text = @"初始化中";
    [self.view addSubview:stateLabel];
    indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(screenw/2 -30,screenh/2 - 30,60 , 60)];
    indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    indicator.frame = CGRectMake(screenw/2 -30,screenh/2 - 30,60 , 60);
    [self.view addSubview:indicator];
    
    bundle = [Utils getSdkBundle];
    
    backBt = [UIButton buttonWithType:UIButtonTypeCustom];
    backBt.frame = CGRectMake(20, 48, 40, 40);
    backBt.imageEdgeInsets = UIEdgeInsetsMake(12, 12, 12, 12);
    NSString *file = [bundle pathForResource:@"back" ofType:@"png"];
    [backBt addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    UIImage *image1 = [UIImage imageWithContentsOfFile:file];
    [backBt setImage:image1 forState:UIControlStateNormal];
    [self.view addSubview:backBt];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [indicator startAnimating];
}

-(void)backClick{
    [[HollyPhoneManager shareManager] unregister];
    [self dismissViewControllerAnimated:false completion:^{
        
    }];
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [indicator stopAnimating];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
